package com.jhws.sys.appUpgrade.service;

import com.jhws.sys.appUpgrade.bo.TblSoftLabelDimBo;
import com.jhws.common.Page;
import com.jhws.core.db.BaseDao;
import com.jhws.sys.appUpgrade.dao.ITblSoftLabelDimDAO;
import com.jhws.util.StringUtils;
import org.apache.commons.collections.MapUtils;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

public class TblSoftLabelDimServiceSpringImpl implements ITblSoftLabelDimService {

    private ITblSoftLabelDimDAO tblSoftLabelDimDAO;

    public ITblSoftLabelDimDAO getTblSoftLabelDimDAO() {
        return tblSoftLabelDimDAO;
    }

    @Resource
    private BaseDao BaseDao;

    public void setTblSoftLabelDimDAO(ITblSoftLabelDimDAO tblSoftLabelDimDAO) {
        this.tblSoftLabelDimDAO = tblSoftLabelDimDAO;
    }

    public TblSoftLabelDimBo save(TblSoftLabelDimBo bo) throws Exception {
        return tblSoftLabelDimDAO.save(bo);
    }

    public List<TblSoftLabelDimBo> findTblSoftLabelDimByWhere(String whereClause) throws Exception {
        return tblSoftLabelDimDAO.findTblSoftLabelDimByWhere(whereClause);
    }

    @Override
    public TblSoftLabelDimBo findTblSoftLabelDimById(String softLabelCode) {
        // TODO Auto-generated method stub
        return tblSoftLabelDimDAO.getById(softLabelCode);
    }

    @Override
    public Page findTblSoftLabelDim(int start, int num, String whereClause) throws Exception {
        Page page = tblSoftLabelDimDAO.findTblSoftLabelDim(start, num, whereClause);
        return page;
    }

    /**
     * 查询标签列表
     *
     * @return
     */
    public Map queryResourcePage(Map param) {
        String hql = "from TblSoftLabelDimBo where 1 = 1 ";
        String softLabe = MapUtils.getString(param, "softLabe");
        if (StringUtils.isNotEmpty(softLabe)) {
            hql += "and soft_labe like '%" + softLabe + "%' ";
        }
        String softLabeName = MapUtils.getString(param, "softLabeName");
        if (StringUtils.isNotEmpty(softLabeName)) {
            hql += "and soft_labe_name like '%" + softLabeName + "%' ";
        }
        return BaseDao.queryPage(hql);
    }

    @Override
    public void removeDim(String softLabelCode) {
        // TODO Auto-generated method stub
        tblSoftLabelDimDAO.deleteTblSoftLabelDim(softLabelCode);
    }

}
